const mongoose = require('./db')
const Schema = mongoose.Schema

const routerSchema = new Schema({
  url: String, //路径
  name: String,   //名称
  icon: String,    //图标
  MenuId: mongoose.Types.ObjectId,  //菜单Id
  component: String,  //组件
  sort: Number,  //排序
  meta:Object,
  
})


const userSchema = new Schema({
  username: String,//用户名
  password: String, //密码
  email: String, //邮箱
  phone: String, //手机
  status: Number, //状态
  rid:mongoose.Types.ObjectId,  //角色
})
const roleShema=new mongoose.Schema({
  name:String, //角色名称
  mid: {
    type: [mongoose.Types.ObjectId],

}
})
//商品集合
const goodsSchema =new mongoose.Schema({
name: String, //商品名称
description: String, //商品描述
price: Number, //商品价格
stock_quantity: Number, //商品库存数量
category: String, //商品类别
brand: String, //商品品牌
release_time: Date, //发布时间
image_url: String, //商品图片URL
is_active: Boolean, //是否上架
created_at: Date, //商品创建时间
updated_at: Date, //商品更新时间,
shop_id: { //商品所属店铺ID
type: mongoose.Schema.Types.ObjectId,
ref: 'shops'
},
})
// 订单集合
const orderSchema =new mongoose.Schema({
  user_id: mongoose.Types.ObjectId, //用户ID
  product_id: mongoose.Types.ObjectId, //商品ID
  quantity: Number, //商品数量
  total_price: Number, //商品总价
  status: String, //订单状态
  created_at: Date, //订单创建时间
  updated_at: Date //订单更新时间
})
const shopShema=new mongoose.Schema({
  name: String,//店铺名称
  description: String,//店铺描述
  location: String,//店铺位置
  img:String,// 店铺图片
  logo: String,//店铺logo
  cover_image: String//店铺封面
})
//购物车
const cartsSchema =new mongoose.Schema({
  user_id: mongoose.Types.ObjectId,
  items: Array,// 商品 和数量
  add_time:Date
})

const roleModel  = mongoose.model("role",roleShema,"role")
// 导出模型
const routerMoudel = mongoose.model('router', routerSchema, 'router')
//登录模型
const userModel = mongoose.model('user', userSchema, 'user')// 用户
const shopModel = mongoose.model('shop', shopShema, 'shop')// 商品
const shopCartModel = mongoose.model('cart', cartsSchema, 'cart')// 购物车
const orderModel= mongoose.model('order', orderSchema, 'order')// 订单
module.exports = {
  userModel,
  routerMoudel,
  roleModel,
  shopModel,
  shopCartModel,
  orderModel
  }